﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.OleDb;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
//using System.Threading.Tasks;

namespace DAL3
{
    public static class SQLHelpaccess
    {
        private static string Con = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\Database.mdb";//第二个参数为文件的路径
                                                                                                      /**/
        public static DataTable readData(string strSQL)
        {
            OleDbConnection dbconn = new OleDbConnection(Con);
            dbconn.Open();//建立连接
            DataSet dataSet = new DataSet();
            OleDbDataAdapter OleDbDA = new OleDbDataAdapter(strSQL, dbconn);
            OleDbDA.Fill(dataSet, "myDataSet");
            dbconn.Close();
            return dataSet.Tables[0];
        }
        
        /// <summary>
        /// 按sql增删改数据
        /// </summary>
        /// <param name="sql"></param>
        /// <returns></returns>
        public static int AddData(string sql)
        {
            OleDbConnection dbconn = new OleDbConnection(Con);
            dbconn.Open();//建立连接
            OleDbCommand myCommand = new OleDbCommand(sql, dbconn);
            //执行命令            
            int result = myCommand.ExecuteNonQuery();
            dbconn.Close();//关闭连接
            return result;
        }

    }
}
